﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data;

using QLTTAN.BLL;
using QLTTAN.DTO;
namespace QLTTAN.Form
{
    public partial class frmKetQuaThiXepLop : DevExpress.XtraEditors.XtraForm
    {

        ThiXepLopBLL TXL_BLL;
        CT_ThiXepLopBLL CT_TXL_BLL;
        TrinhDoBLL TD_BLL;

        public int MaTXLSelected = -1;        

        public frmKetQuaThiXepLop()
        {
            InitializeComponent();
        }

        private void FillDataInriLookUpEditTrinhDoDatDuoc()
        {
            riLookUpEditTrinhDoTuongUng.DataSource = TD_BLL.TrinhDo_Load();
            riLookUpEditTrinhDoTuongUng.ValueMember = "MaTrinhDo";
            riLookUpEditTrinhDoTuongUng.DisplayMember = "TenTrinhDo";
        }

        private void frmKetQuaThiXepLop_Load(object sender, EventArgs e)
        {
            TXL_BLL = new ThiXepLopBLL();
            CT_TXL_BLL = new CT_ThiXepLopBLL();
            TD_BLL = new TrinhDoBLL();

            FillDataInriLookUpEditTrinhDoDatDuoc();

            try
            {
                ThiXepLopDTO TXL_DTO = new ThiXepLopDTO();
                TXL_DTO.MaTXL = MaTXLSelected;

                DataRow TXLSelected = TXL_BLL.ThiXepLop_GetInfo(TXL_DTO);
                txtNgayThi.Text = TXLSelected["NgayThi"].ToString();
                txtPhongThi.Text = TXLSelected["TenPhong"].ToString();
                txtThoiGianThi.Text = TXLSelected["ThoiGianThi"].ToString();
                txtSiSo.Text = TXLSelected["SiSo"].ToString();
                txtKhoaHoc.Text = TXLSelected["TenKhoaHoc"].ToString();
                txtChuongTrinhThi.Text = TXLSelected["TenLoaiCT"].ToString();
                txtDeThi.Text = TXLSelected["TenDeThi"].ToString();
                txtThoiLuongThi.Text = TXLSelected["ThoiLuongThi"].ToString();

                // Load danh sách học viên.
                CT_ThiXepLopDTO CT_TXL_DTO = new CT_ThiXepLopDTO();
                CT_TXL_DTO.MaTXL = MaTXLSelected;

                gridCtrlHocVien.DataSource = CT_TXL_BLL.CT_ThiXepLop_Load(CT_TXL_DTO);

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Thông báo!!!", MessageBoxButtons.OK);
            }
        }

        private void btnXuat_Click(object sender, EventArgs e)
        {

        }

        private void btnNhapDiem_Click(object sender, EventArgs e)
        {
            Diem.OptionsColumn.AllowEdit = true;
            TrinhDoDatDuoc.OptionsColumn.AllowEdit = true;
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                CT_ThiXepLopDTO CT_TXL_DTO = new CT_ThiXepLopDTO();
                CT_TXL_DTO.MaTXL = MaTXLSelected;

                for (int i = 0; i < gridViewHocVien.RowCount; i++)
                {
                    DataRow row = gridViewHocVien.GetDataRow(i);

                    CT_TXL_DTO.MaHV = int.Parse(row["MaHV"].ToString());
                    CT_TXL_DTO.Diem = int.Parse(row["Diem"].ToString());
                    CT_TXL_DTO.TrinhDoDatDuoc = int.Parse(row["TrinhDoDatDuoc"].ToString());

                    CT_TXL_BLL.CT_ThiXepLop_Update(CT_TXL_DTO);
                }

                gridCtrlHocVien.DataSource = CT_TXL_BLL.CT_ThiXepLop_Load(CT_TXL_DTO);

            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Thông báo!!!", MessageBoxButtons.OK);
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show("Bạn có chắc chắn muốn thoát khỏi màn hình Kết Quả Thi Thi Xếp Lớp?\n Mọi thao tác của bạn sẽ không được lưu lại.",
                                   "Thông báo!!!", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                this.Close();
        }

        private void gridViewHocVien_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.FieldName == "STT")
                e.DisplayText = (e.ListSourceRowIndex + 1).ToString();
        }
    }
}